package com.yao.club.reposittory;


import com.yao.club.entity.dto.InformationDetail;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;



@Repository
public interface InformationDetailRepository extends JpaRepository<InformationDetail, String> {

    /**
     * 分页查询指定类型的资讯
     */
    Page<InformationDetail> findByInformationTypeIdOrderByCreateTimeDesc(
            String informationTypeId,
            Pageable pageable);

    /**
     * 根据关键字搜索资讯
     */
    @Query("SELECT i FROM InformationDetail i WHERE  "+
            "(i.content LIKE %:keyword%) " +
            "ORDER BY i.createTime DESC")
    Page<InformationDetail> findByKeyword(
            @Param("keyword") String keyword,
            Pageable pageable);

    /**
     * 根据类型和关键字搜索资讯
     */
    @Query("SELECT i FROM InformationDetail i WHERE  " +
            "i.informationTypeId = :typeId " +
            "AND (i.content LIKE %:keyword%) " +
            "ORDER BY i.createTime DESC")
    Page<InformationDetail> findByTypeIdAndKeyword(
            @Param("typeId") String typeId,
            @Param("keyword") String keyword,
            Pageable pageable);

}
